'''数据预处理过程中需要的数学处理函数
'''
import numpy as np
num_to_alpha_dict={'10': 'a', '11': 'b', '12': 'c','13':'d','14':'e','15':'f','16':'g','17':'h','18':'i','19':'j',
                            '20':'k','21':'l','22':'m','23':'n','24':'o','25':'p','26':'q','27':'r','28':'s','29':'t',
                            '30':'u','31':'v','32':'w','33':'x','34':'y','35':'z'}
alpha_to_num_dict={}
for key,val in num_to_alpha_dict.items():
    alpha_to_num_dict[val]=key

def divide_two_box(x, y, w, h):
    '''
    将一个矩形分割成两个矩形
    :param x: 原矩形左上角x坐标
    :param y: 原矩形左上角y坐标
    :param w: 原矩形的宽
    :param h: 原矩形的高
    :return: rect_left:左侧矩形的四个角点坐标
                 rect_right右侧矩形的四个角点坐标
    '''
    rect_left = np.int64([[x, y], [x + w / 2, y], [x + w / 2, y + h], [x, y + h]])
    rect_right = np.int64([[x + w / 2, y], [x + w, y], [x + w, y + h], [x + w / 2, y + h]])
    return rect_left, rect_right


def divide_three_box(x, y, w, h):
    '''
    将一个矩形分割成两个矩形
    :param x: 原矩形左上角x坐标
    :param y: 原矩形左上角y坐标
    :param w: 原矩形的宽
    :param h: 原矩形的高
    :return: rect_left:左侧矩形的四个角点坐标
                 rect_mid:中间矩形四个角点坐标
                 rect_right右侧矩形的四个角点坐标
    '''
    rect_left = np.int64([[x, y], [x + w / 3, y], [x + w / 3, y + h], [x, y + h]])
    rect_mid = np.int64([[x + w / 3, y], [x + w * 2 / 3, y], [x + w * 2 / 3, y + h], [x + w / 3, y + h]])
    rect_right = np.int64([[x + w * 2 / 3, y], [x + w, y], [x + w, y + h], [x + w * 2 / 3, y + h]])
    return rect_left, rect_mid, rect_right

def take_first(elem):
    '''
    获取列表中第一个元素
    :param elem:
    :return: 返回第一个元素
    '''
    return elem[0]

def take_second(elem):
    '''
    获取列表中第二个元素
    :param elem:
    :return: 返回第二个元素
    '''
    return elem[1]

def label_alpha_to_number(train_label):

    i = 0
    for item in train_label:
        temp = ord(item)
        if temp >= 97:
            train_label[i] = int(alpha_to_num_dict[item])
        else:
            train_label[i] = int(item)
        i += 1
    return train_label

def show_verification_code(code_list):
    '''
    显示验证码
    :param code_list: 存放验证码的列表
    :return: 6位验证码
    '''
    a=''
    for i in range(len(code_list)):
        a+=code_list[i]
    return a


